package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.server.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/users")
@Slf4j
public class UserInfoController {

    @Autowired
    private UserService userService;

    /**
     *接口名称：用户资料 - 读取
     * 接口路径：GET/users
     */
    @GetMapping
    public ResponseEntity  findUserInfoById(Long userID,Long huanxinID){
        return userService.findUserInfoById(userID,huanxinID);
    }

    /**
     *接口名称：用户资料 - 保存
     *接口路径：PUT/users
     */
    @PutMapping
    public ResponseEntity  updateUserInfo(@RequestHeader("Authorization")String token,@RequestBody UserInfo userInfo){
        return userService.updateUserInfo(userInfo,token);
    }


    /**
     *接口名称：互相喜欢，喜欢，粉丝 - 统计
     * 接口路径：GET/users/counts
     */
    @GetMapping("/counts")
    public ResponseEntity  queryCounts(){
        return userService.queryCounts();
    }


    /**
     *接口名称：互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表、
     *接口路径：GET/users/friends/:type
     *
     */
    @GetMapping("/friends/{type}")
    public ResponseEntity  queryUserLikeList(@PathVariable("type") Integer type,
                                             @RequestParam(defaultValue = "1") Integer page,
                                             @RequestParam(defaultValue = "10") Integer pagesize){
        return userService.queryUserLikeList(type,page,pagesize);
    }

    /**
     *接口名称：粉丝 - 喜欢
     * 接口路径：POST/users/fans/:uid
     *
     */
    @PostMapping("/fans/{uid}")
    public ResponseEntity  fansLike(@PathVariable("uid")Long fansId){
        return userService.fansLike(fansId);
    }

    @RequestMapping(value = "/{uid}/alreadyLove",method = RequestMethod.GET)
    public ResponseEntity<Object> alreadyLove(@PathVariable("uid")long uid) throws IOException {
        ResponseEntity<Object> alreadLove = userService.alreadLove(uid);
        return alreadLove;
    }
}
